﻿namespace Devonline.Entity;

/// <summary>
/// 销售订单
/// </summary>
[DisplayName("销售订单")]
public class SaleOrderViewModel : SaleOrderViewModel<string>, IViewModel, IEntitySet
{
    /// <summary>
    /// 下单客户
    /// </summary>
    public virtual CustomerViewModel? Customer { get; set; }
    /// <summary>
    /// 销售订单明细
    /// </summary>
    public virtual ICollection<SaleOrderDetailViewModel>? Details { get; set; }
    /// <summary>
    /// 销售订单支付记录
    /// </summary>
    public virtual ICollection<SaleOrderPaymentRecord>? PaymentRecords { get; set; }
}

/// <summary>
/// 销售订单
/// </summary>
/// <typeparam name="TKey"></typeparam>
[DisplayName("销售订单")]
public abstract class SaleOrderViewModel<TKey> : ViewModel<TKey>, IViewModel<TKey>, IEntitySet<TKey> where TKey : IConvertible
{
    /// <summary>
    /// 客户编号
    /// </summary>
    [DisplayName("客户编号"), Required, MaxLength(36), Excel]
    public virtual TKey CustomerId { get; set; } = default!;
    /// <summary>
    /// 订单号
    /// </summary>
    [Required, MaxLength(36), DisplayName("订单号")]
    public virtual string OrderNumber { get; set; } = null!;
    /// <summary>
    /// 订单金额
    /// </summary>
    [DisplayName("订单金额"), Excel]
    public virtual decimal Amount { get; set; }
    /// <summary>
    /// 支付方式
    /// </summary>
    [DisplayName("支付方式"), DefaultValue(PaymentType.WeixinPay), Excel]
    public virtual PaymentType PaymentType { get; set; }
    /// <summary>
    /// 总重
    /// </summary>
    [DisplayName("总重"), Excel]
    public virtual decimal? Weight { get; set; }
    /// <summary>
    /// 运费
    /// </summary>
    [DisplayName("运费"), Excel]
    public virtual decimal? Freight { get; set; }
    /// <summary>
    /// 运单号
    /// </summary>
    [MaxLength(36), DisplayName("运单号")]
    public virtual string? TrackingNumber { get; set; }
    /// <summary>
    /// 发货时间
    /// </summary>
    [DisplayName("发货时间"), Excel]
    public virtual DateTime? ShippingTime { get; set; }
    /// <summary>
    /// 到货时间
    /// </summary>
    [DisplayName("到货时间"), Excel]
    public virtual DateTime? DeliverTime { get; set; }
    /// <summary>
    /// 备注说明
    /// </summary>
    [DisplayName("备注说明"), MaxLength(1024), Excel]
    public virtual string? Description { get; set; }
}

/// <summary>
/// 销售订单明细
/// </summary>
[DisplayName("销售订单明细")]
public class SaleOrderDetailViewModel : SaleOrderDetailViewModel<string>, IViewModel, IEntitySet
{
    /// <summary>
    /// 订单
    /// </summary>
    public virtual SaleOrderViewModel? Order { get; set; }
    /// <summary>
    /// 货品
    /// </summary>
    public virtual ProductViewModel? Product { get; set; }
}

/// <summary>
/// 销售订单明细
/// </summary>
[DisplayName("销售订单明细")]
public abstract class SaleOrderDetailViewModel<TKey> : ViewModel<TKey>, IViewModel<TKey>, IEntitySet<TKey> where TKey : IConvertible
{
    /// <summary>
    /// 订单编号
    /// </summary>
    [Required, MaxLength(36), DisplayName("订单编号")]
    public virtual TKey OrderId { get; set; } = default!;
    /// <summary>
    /// 货品编号
    /// </summary>
    [Required, MaxLength(36), DisplayName("货品编号"), Excel]
    public virtual TKey ProductId { get; set; } = default!;
    /// <summary>
    /// 单价
    /// </summary>
    [DisplayName("单价"), Excel]
    public virtual decimal Price { get; set; }
    /// <summary>
    /// 数量
    /// </summary>
    [DisplayName("数量"), Excel]
    public virtual decimal Count { get; set; }
}